//
//  ViewController.m
//  Calculator
//
//  Created by 解晓东 on 15/11/15.
//  Copyright (c) 2015年 sasa. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, weak) IBOutlet UITextField *num1TextField;
@property (nonatomic, weak) IBOutlet UITextField *num2TextField;
@property (nonatomic, weak) IBOutlet UILabel *resultLabel;

@end

@implementation ViewController

/*
  视图加载完成会被执行
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSLog(@"视图加载完成！");
}

#pragma mark - 计算
- (IBAction)compute {
    NSLog(@"计算");
    // 1.得到两个文本框的值
    NSString *num1Str = self.num1TextField.text;
    NSString *num2Str = self.num2TextField.text;
    
    // 2.将值转化为整形
    int num1 = num1Str.intValue;
    int num2 = num2Str.intValue;
    
    // 3.计算并显示
    int result = num1 + num2;
    self.resultLabel.text = [NSString stringWithFormat:@"%d", result];

    // 关闭键盘，这里是注销第一响应者
//    [self.num1TextField resignFirstResponder];
//    [self.num2TextField resignFirstResponder];
    
    // 关闭键盘，这里是让视图关闭键盘，无论现在谁是第一响应者
    [self.view endEditing:YES];
}

@end
